From 56db20dffadf13f76c502872ccbe75398e996e3a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Feb 2016 23:58:27 -0800 Subject: [PATCH] Make Config::get private Don't actually want to expose this, callers need to use the more concrete methods anyway. --- src/cargo/ops/cargo_compile.rs | 63 +++++++++++++++++----------------- src/cargo/util/config.rs | 4 +-- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 5226a8aee..8aa6b9878 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -32,7 +32,7 @@ use core::{Source, SourceId, SourceMap, PackageSet, Package, Target}; use core::{Profile, TargetKind, Profiles}; use core::resolver::{Method, Resolve}; use ops::{self, BuildOutput, ExecEngine}; -use util::config::{ConfigValue, Config}; +use util::config::Config; use util::{CargoResult, internal, ChainError, profile}; /// Contains information about how a package should be compiled. @@ -479,37 +479,36 @@ fn scrape_target_config(config: &Config, triple: &str) let table = try!(config.get_table(&key)).unwrap().val; for (k, _) in table.into_iter() { let key = format!("{}.{}", key, k); - match try!(config.get(&key)).unwrap() { - ConfigValue::String(v, path) => { - if k == "rustc-flags" { - let whence = format!("in `{}` (in {})", key, - path.display()); - let (paths, links) = try!( - BuildOutput::parse_rustc_flags(&v, &whence) - ); - output.library_paths.extend(paths.into_iter()); - output.library_links.extend(links.into_iter()); - } else { - output.metadata.push((k, v)); - } - }, - ConfigValue::List(a, p) => { - if k == "rustc-link-lib" { - output.library_links.extend(a.into_iter().map(|v| v.0)); - } else if k == "rustc-link-search" { - output.library_paths.extend(a.into_iter().map(|v| { - PathBuf::from(&v.0) - })); - } else if k == "rustc-cfg" { - output.cfgs.extend(a.into_iter().map(|v| v.0)); - } else { - try!(config.expected("string", &k, - ConfigValue::List(a, p))); - } - }, - // technically could be a list too, but that's the exception to - // the rule... - cv => { try!(config.expected("string", &k, cv)); } + match &k[..] { + "rustc-flags" => { + let flags = try!(config.get_string(&key)).unwrap(); + let whence = format!("in `{}` (in {})", key, + flags.definition); + let (paths, links) = try!( + BuildOutput::parse_rustc_flags(&flags.val, &whence) + ); + output.library_paths.extend(paths.into_iter()); + output.library_links.extend(links.into_iter()); + } + "rustc-link-lib" => { + let list = try!(config.get_list(&key)).unwrap(); + output.library_links.extend(list.val.into_iter() + .map(|v| v.0)); + } + "rustc-link-search" => { + let list = try!(config.get_list(&key)).unwrap(); + output.library_paths.extend(list.val.into_iter().map(|v| { + PathBuf::from(&v.0) + })); + } + "rustc-cfg" => { + let list = try!(config.get_list(&key)).unwrap(); + output.cfgs.extend(list.val.into_iter().map(|v| v.0)); + } + _ => { + let val = try!(config.get_string(&key)).unwrap(); + output.metadata.push((k, val.val)); + } } } ret.overrides.insert(lib_name, output); diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 5160a91f7..b2361e74d 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -117,7 +117,7 @@ impl Config { *self.target_dir.borrow_mut() = Some(path.to_owned()); } - pub fn get(&self, key: &str) -> CargoResult> { + fn get(&self, key: &str) -> CargoResult> { let vals = try!(self.values()); let mut parts = key.split('.').enumerate(); let mut val = match vals.get(parts.next().unwrap().1) { @@ -496,7 +496,7 @@ impl ConfigValue { } impl Definition { - pub fn root<'a>(&'a self, config: &'a Config) -> &'a Path { + pub fn root<'a>(&'a self, _config: &'a Config) -> &'a Path { match *self { Definition::Path(ref p) => p.parent().unwrap().parent().unwrap(), } -- 2.30.2